//
//  CourseTableViewCell.m
//  TeacherNet
//
//  Created by slz on 2017/11/8.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "CourseTableViewCell.h"

@implementation CourseTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        _courseImageView = [UIImageView new];
        _courseImageView.contentMode = UIViewContentModeScaleAspectFill;
        _courseImageView.layer.masksToBounds = YES;
        _courseStudentIcon = [UIImageView new];
        _courseName = [UILabel new];
        _courseTeacher = [UILabel new];
        _coursePrice = [UILabel new];
        _courseStudentCount = [UILabel new];
        _courseTeacherTitle = [UILabel new];
        UIView * lineView = [UIView new];
        
        [self.contentView addSubview:_courseImageView];
        [self.contentView addSubview:_courseStudentIcon];
        [self.contentView addSubview:_courseName];
        [self.contentView addSubview:_courseTeacher];
        [self.contentView addSubview:_coursePrice];
        [self.contentView addSubview:_courseStudentCount];
        [self.contentView addSubview:_courseTeacherTitle];
        [self.contentView addSubview:lineView];
        
        [_courseImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(11);
            make.top.mas_equalTo(self.contentView.mas_top).offset(11);
            make.size.mas_equalTo(CGSizeMake(102, 58));
        }];
        
        _courseStudentIcon.image = [UIImage imageNamed:@"home_course_cell_user"];
        [_courseStudentIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseImageView.mas_right).offset(5);
            make.bottom.mas_equalTo(_courseImageView.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(13, 13));
        }];
        
        _courseName.textColor = kDark_TextColor_Default;
        _courseName.fontSize = 16;
        [_courseName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseImageView.mas_right).offset(8);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-8);
            make.top.mas_equalTo(_courseImageView.mas_top);
        }];
        
        _courseTeacher.textColor = kLight_TextColor_Default;
        _courseTeacher.fontSize = 12;
        [_courseTeacher mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseImageView.mas_right).offset(8);
            make.top.mas_equalTo(_courseName.mas_bottom).offset(5);
        }];
        
        _courseTeacherTitle.textColor = _courseTeacher.textColor;
        _courseTeacherTitle.fontSize = 12;
        [_courseTeacherTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseTeacher.mas_right).offset(5);
            make.top.mas_equalTo(_courseTeacher.mas_top);
        }];
        
        _courseStudentCount.textColor = _courseTeacher.textColor;
        _courseStudentCount.fontSize = 12;
        [_courseStudentCount mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseStudentIcon.mas_right).offset(5);
            make.bottom.mas_equalTo(_courseImageView.mas_bottom);
        }];
        
        _coursePrice.textColor = [UIColor redColor];
        _coursePrice.fontSize = 14;
        [_coursePrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).offset(-27);
            make.bottom.mas_equalTo(_courseImageView.mas_bottom);
        }];
        
        lineView.backgroundColor = kLineColor_Gray_Default;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.and.bottom.mas_equalTo(self.contentView);
            make.height.mas_equalTo(1);
        }];
    }
    return self;
}

-(void)layoutWithModel:(CourseModel *)model
{
    [self.courseImageView setImageWithURL:[NSURL URLWithString:kAPI_IMAGE_HOST(model.courseImage)]];
    self.courseName.text = model.courseName;
    self.coursePrice.text = [NSString stringWithFormat:@"%@%@",@"¥",model.coursePrice];
    self.courseTeacher.text = model.courseTeacher;
    self.courseStudentCount.text = model.studentCount;
    self.courseTeacherTitle.text = model.courseTeacherTitle;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
